package com.hua.yuan.live.view.holder_view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hua.yuan.common.BaseHolderView;
import com.hua.yuan.live.R;
import com.hua.yuan.live.repertory.cloud_data.res.ChatMsgBean;

import java.util.List;

/**
 * 私信页面的布局
 */
public class HolderView_PrivateChat implements BaseHolderView<ChatMsgBean>{

    private LinearLayout mLeftLayout;
    private LinearLayout mRightLayout;
    private TextView mLeftMsg;
    private TextView mRightMsg;

    public HolderView_PrivateChat(View pView, int pPosition) {

        mLeftLayout=(LinearLayout)pView.findViewById(R.id.left_layout_private_chat);
        mRightLayout=(LinearLayout)pView.findViewById(R.id.right_layout_private_chat);
        mLeftMsg=(TextView)pView.findViewById(R.id.left_msg_private_chat);
        mRightMsg=(TextView)pView.findViewById(R.id.right_msg_private_chat);
    }
    @SuppressLint({"StringFormatInvalid", "StringFormatMatches"})
    @Override
    public void bindHolder(@NonNull List<ChatMsgBean> pList, int position, @NonNull Context pContext) {

        if (pList == null || pList.size() == 0 || (position > pList.size())) {
            return;
        }

        ChatMsgBean msg=pList.get(position);

        if(msg==null){
            return;
        }
        //增加对消息类的判断，如果这条消息是收到的，显示左边布局，是发出的，显示右边布局
        if(msg.getType()==ChatMsgBean.TYPE_RECEIVED){
            mLeftLayout.setVisibility(View.VISIBLE);
            mRightLayout.setVisibility(View.GONE);
            mLeftMsg.setText(msg.getContent());
        }else if(msg.getType()==ChatMsgBean.TYPE_SENT) {
            mRightMsg.setVisibility(View.VISIBLE);
            mLeftMsg.setVisibility(View.GONE);
            mRightMsg.setText(msg.getContent());
        }


    }

}
